package com.bjqg.bjqg01.bjqg.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bjqg.bjqg01.bjqg.R;


/**
 * Created by bjqg01 on 2017/10/9.
 */
public class GridViewAdapter extends BaseAdapter {

    private Context context=null;
    private String data[]=null;
    private int imgId[]=null;
    private LayoutInflater inflater;

    private class Holder{

        TextView noticeNum ;
        ImageView item_img;
        TextView item_tex;

        public ImageView getItem_img() {
            return item_img;
        }

        public void setItem_img(ImageView item_img) {
            this.item_img = item_img;
        }

        public TextView getItem_tex() {
            return item_tex;
        }

        public void setItem_tex(TextView item_tex) {
            this.item_tex = item_tex;
        }

        public TextView getNoticeNum() {
            return noticeNum;
        }

        public void setNoticeNum(TextView noticeNum) {
            this.noticeNum = noticeNum;
        }
    }
    //构造方法
    public GridViewAdapter(Context context, String[] data, int[] imgId) {
        this.context = context;
        this.data = data;
        this.imgId = imgId;
        inflater= LayoutInflater.from(context);
    }


    @Override
    public int getCount() {


        return data.length;

    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        Holder holder;
        if(view==null){
            view=inflater.inflate(R.layout.layout_item_gridview,null);
            holder=new Holder();
            holder.noticeNum = (TextView) view.findViewById(R.id.noticeNumber);
            if (position>0){

                holder.noticeNum.setVisibility(View.GONE);
            }
            holder.item_img=(ImageView)view.findViewById(R.id.item_img);
            holder.item_tex=(TextView)view.findViewById(R.id.item_text);
            view.setTag(holder);
        }else{
            holder=(Holder) view.getTag();
        }
        holder.item_tex.setText(data[position]);
        holder.item_img.setImageResource(imgId[position]);

        return view;
    }
}

